#include "Wnd.h"
#include "Util/Util.h"
#include "debug_new.h"


CWnd::CWnd():
m_hInst(NULL),
m_hWnd(NULL),
m_hWndParent(NULL),
m_bCreated(FALSE),
m_hEventCreated(NULL),
m_bMsgThrdInside(FALSE)  
{
	
}

CWnd::~CWnd()
{
#ifndef UNDER_CE
	_CrtDumpMemoryLeaks();
#endif
}

//----------------------------------------------------------------------
//Description:
//    Create the window
//
//Parameters:
//    hInst : [in] The handle of instance of the application
//    hWndParent : [in] The parent window
//    pcszWndClass : [in] The class of the window
//    pcszWndName : [in] The name of the windows
//    bMsgThrdInside : [in] The message thread process is inside or not
//
//----------------------------------------------------------------------
BOOL CWnd::Create(HINSTANCE hInst, HWND hWndParent,wstring strWndClass,wstring strWndName,BOOL bMsgThrdInside)
{
    m_hInst = hInst;
    m_hWndParent = hWndParent;
    m_bMsgThrdInside = bMsgThrdInside;

	m_strWndClass = strWndClass;
	m_strWndName = strWndName;

    //Create the window
    if(bMsgThrdInside == TRUE)
    {
        HANDLE hdThrd = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)CreateProc,this,0,NULL);
        if(hdThrd == NULL )
        {
            return FALSE;
        }
        else
        {
            CloseHandle(hdThrd);
            //Create the event and wait
            m_hEventCreated = CreateEvent(NULL,FALSE,FALSE,NULL);
            if(m_hEventCreated != NULL)
            {
                WaitForSingleObject(m_hEventCreated,INFINITE);
                CloseHandle(m_hEventCreated);
                m_hEventCreated = NULL;
                return m_bCreated;
            }
            else
            {
                return FALSE;
            }
        }
    }
    else
    {
        return CreateWnd();
    }
}

//----------------------------------------------------------------------
//Description:
//    Register window
//
//----------------------------------------------------------------------
BOOL CWnd::RegisterWnd(HINSTANCE hInst,const TCHAR *pcszWndClass)
{    
    WNDCLASS wc = {0};
    wc.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
    wc.lpfnWndProc   = (WNDPROC)CWnd::StaticWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = m_hInst;
    wc.hIcon         = NULL; 
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = NULL;//(HBRUSH)GetSysColorBrush(COLOR_BACKGROUND);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = pcszWndClass;

    return RegisterClass(&wc);
}


//----------------------------------------------------------------------
//Description:
//    Static WndProc wrapper and actual WndProc
//
//----------------------------------------------------------------------
LRESULT CWnd::StaticWndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
    CWnd *pObject = (CWnd*)GetWindowLong(hWnd, GWL_USERDATA);

    if(pObject)
    {
        return pObject->WndProc(hWnd,wMsg,wParam,lParam);
    }
    else
    {
        return DefWindowProc(hWnd,wMsg,wParam,lParam);
    }
}

//----------------------------------------------------------------------
//Description:
//    Actual WndProc
//
//----------------------------------------------------------------------
LRESULT CWnd::WndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
    switch(wMsg)
    {
    case WM_DESTROY:
        OnDestroy(hWnd,wMsg,wParam,lParam);
        break;
    }
    return DefWindowProc(hWnd,wMsg,wParam,lParam);
}


//----------------------------------------------------------------------
//Description:
//    Show the window
//
//----------------------------------------------------------------------
BOOL CWnd::ShowWindow(BOOL bShow)
{
    if(m_hWnd == NULL)
    {
        return FALSE;
    }

    if(bShow == TRUE)
    {
        SetForegroundWindow(m_hWnd);
        SetWindowPos(m_hWnd,HWND_TOP,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);            
    }
    else
    {
        ::ShowWindow(m_hWnd,SW_HIDE);
    }

    return TRUE;
}

//----------------------------------------------------------------------
//Description:
//    The process thread is for creating the window
//
//----------------------------------------------------------------------
DWORD CWnd::CreateProc(PVOID pArg)
{
    //Get the object instance
    CWnd *pObject = (CWnd *)pArg;

    //Create the window
    pObject->m_bCreated = pObject->CreateWnd();

    //Set the event
    if(pObject->m_hEventCreated != NULL)
    {
        SetEvent(pObject->m_hEventCreated);
    }

    if(pObject->m_bCreated == FALSE)
    {
        //Failed in creating the window, so return and needn't the message loop
        return 0x01;
    }

    //The message loop
    MSG msg;
    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return 0;
}

//----------------------------------------------------------------------
//Description:
//    Create the window
//
//----------------------------------------------------------------------
BOOL CWnd::CreateWnd(void)
{
    if(RegisterWnd(m_hInst,m_strWndClass.c_str()) == FALSE)
    {
        return FALSE;
    }

    RECT rcArea = {0};

#ifdef UNDER_CE
    SystemParametersInfo(SPI_GETWORKAREA, 0, &rcArea, 0);
#else
	//SetRect(&rcArea,0,0,CUtil::GetScreenWidth(),CUtil::GetScreenHeight());
	SetRect(&rcArea,0,0,0,0);
#endif

    m_hWnd = CreateWindowEx(WS_EX_TOPMOST,
        m_strWndClass.c_str(),
        m_strWndName.c_str(),
        WS_POPUP,
        rcArea.left,
        rcArea.top,
        rcArea.right - rcArea.left,
        rcArea.bottom - rcArea.top,
        m_hWndParent,
        NULL,
        m_hInst, 
        0);

    if (IsWindow(m_hWnd) == FALSE)
    {
        return FALSE;
    }

    // If the window is created successfully, store this object so the 
    //static wrapper can pass calls to the real WndProc.
    SetWindowLong(m_hWnd, GWL_USERDATA, (DWORD)this);

    return OnCreate();
}

BOOL CWnd::OnCreate()
{
    return TRUE;
}

//----------------------------------------------------------------------
//Description:
//    On Message WM_DESTROY
//
//----------------------------------------------------------------------
void CWnd::OnDestroy(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
    if(m_bMsgThrdInside == TRUE)
    {
        PostQuitMessage(0x00);
    }
}

void FunAniMskVMiddle2Side(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

#ifdef UNDER_CE
	HBITMAP hMaskBmp = CUtil::LoadBitmapEx(L"MaskAni.bmp",TRUE);
#else
	HBITMAP hMaskBmp = CUtil::LoadBitmapEx(L"MaskAni.bmp",FALSE);
#endif

	HBITMAP hOldBmp = NULL;

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;

	int i = 17;
	CRect rcTop = m_rcClient;
	CRect rcBottom = m_rcClient;

	rcTop.bottom = rcTop.top + 8;
	rcBottom.top = rcBottom.bottom - 8;


	while(i--)
	{
		dc.AlphaBlendEx(rcTop,hMaskBmp,	rcTop,100);
		dc.AlphaBlendEx(rcBottom,hMaskBmp,rcBottom,100);
		rcTop.OffsetRect(0,8);
		rcBottom.OffsetRect(0,-8);
		Sleep(nSleepEscap);
	}

	DeleteObject(hMaskBmp);
	hMaskBmp = NULL;

	//DWORD dwT2 = GetTickCount();
	//dwT2 -= dwT1;

	if(!bMsgBox)
	{
		i = 16;
		CRect rcTmp = m_rcClient;
		rcTmp.bottom = rcTmp.top = m_rcClient.Height()/2;
		pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
		if(!bExitAni)
		{
			pCT->Paint(pMemDC);
		}
		else
		{
			hOldBmp = pMemDC->SelectBitmap(hBitmap);
		}

		while (i--)
		{
			rcTmp.DeflateRect(0,-8,0,-8);
			dc.BitBlt(rcTmp.left,rcTmp.top,rcTmp.Width(),rcTmp.Height(),pMemDC->m_hDC,rcTmp.left,rcTmp.top,SRCCOPY);
			Sleep(nSleepEscap);
		}

		delete pMemDC;
		pMemDC = NULL;
	}
}

void FunAniVMiddle2Side(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	//HBITMAP hMaskBmp = CUtil::LoadBitmapEx(strAniMask,bFromDll);
//#ifdef UNDER_CE
	//HBITMAP hMaskBmp = CUtil::LoadBitmapEx(L"MaskAni.bmp",TRUE);
//#else
	//HBITMAP hMaskBmp = CUtil::LoadBitmapEx(L"MaskAni.bmp",FALSE);
//#endif

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;
	int i = 16;

	CRect rcTmp = m_rcClient;
	rcTmp.bottom = rcTmp.top = m_rcClient.Height()/2;
	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	//pCT->Paint(pMemDC);

	if(!bExitAni)
	{
		pCT->Paint(pMemDC);
	}
	else
	{
		pMemDC->SelectBitmap(hBitmap);
	}

	while (i--)
	{
		rcTmp.DeflateRect(0,-8,0,-8);
		dc.BitBlt(rcTmp.left,rcTmp.top,rcTmp.Width(),rcTmp.Height(),pMemDC->m_hDC,rcTmp.left,rcTmp.top,SRCCOPY);
		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;

}

void FunAniMskHMiddle2Side(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;

	//HBITMAP hMaskBmp = CUtil::LoadBitmapEx(strAniMask,bFromDll);
#ifdef UNDER_CE
	HBITMAP hMaskBmp = CUtil::LoadBitmapEx(L"MaskAni.bmp",TRUE);
#else
	HBITMAP hMaskBmp = CUtil::LoadBitmapEx(L"MaskAni.bmp",FALSE);
#endif

	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 8;
	}
	else if (m_rcClient.Width() == 800)
	{
		nWidth = 20;
	}
	else
	{
		nWidth = 12;
	}
	i = m_rcClient.Width()/(nWidth*2);
	CRect rcLeft = m_rcClient;
	CRect rcRight = m_rcClient;

	rcLeft.right = rcLeft.left + nWidth;
	rcRight.left = rcRight.right - nWidth;

	while(i--)
	{
		dc.AlphaBlendEx(rcLeft,hMaskBmp,rcLeft,100);
		dc.AlphaBlendEx(rcRight,hMaskBmp,rcRight,100);
		rcLeft.OffsetRect(nWidth,0);
		rcRight.OffsetRect(-nWidth,0);
		Sleep(nSleepEscap);
	}

	DeleteObject(hMaskBmp);
	hMaskBmp = NULL;

	//DWORD dwT2 = GetTickCount();
	//dwT2 -= dwT1;

	if(!bMsgBox)
	{
		i = m_rcClient.Width()/nWidth;
		CRect rcTmp = m_rcClient;
		rcTmp.left = rcTmp.right = m_rcClient.Width()/2;
		pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
		if(!bExitAni)
		{
			pCT->Paint(pMemDC);
		}
		else
		{
			pMemDC->SelectBitmap(hBitmap);
		}

		while (i--)
		{
			rcTmp.DeflateRect(-nWidth,0,-nWidth,0);
			dc.BitBlt(rcTmp.left,rcTmp.top,rcTmp.Width(),rcTmp.Height(),pMemDC->m_hDC,rcTmp.left,rcTmp.top,SRCCOPY);
			Sleep(nSleepEscap);
		}

		delete pMemDC;
		pMemDC = NULL;
	}
}



void FunAniHMiddle2Side(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;
	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 8;
	}
	else if (m_rcClient.Width() == 800)
	{
		nWidth = 20;
	}
	else
	{
		nWidth = 12;
	}
	i = m_rcClient.Width()/(nWidth*2);
	CRect rcTmp = m_rcClient;
	rcTmp.left = rcTmp.right = m_rcClient.Width()/2;
	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	if(!bExitAni)
	{
		pCT->Paint(pMemDC);
	}
	else
	{
		pMemDC->SelectBitmap(hBitmap);
	}

	while (i--)
	{
		rcTmp.DeflateRect(-nWidth,0,-nWidth,0);
		dc.BitBlt(rcTmp.left,rcTmp.top,rcTmp.Width(),rcTmp.Height(),pMemDC->m_hDC,rcTmp.left,rcTmp.top,SRCCOPY);
		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;
}


void FunAniSlide2Left(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;
	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 16;
	}
	else if (m_rcClient.Width() == 800)
	{
		nWidth = 40;
	}
	else if (m_rcClient.Width() >= 800)
	{
		nWidth = 60;
	}
	else
	{
		nWidth = 24;
	}
	i = m_rcClient.Width()/nWidth;

	CRect rcTmp = m_rcClient;
	rcTmp.OffsetRect(m_rcClient.Width(),0);

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	if(!bExitAni)
	{
		pCT->Paint(pMemDC);
	}
	else
	{
		pMemDC->SelectBitmap(hBitmap);
	}

	while (i--)
	{
		rcTmp.OffsetRect(-nWidth,0);
		dc.BitBlt(rcTmp.left,rcTmp.top,rcTmp.Width(),rcTmp.Height(),pMemDC->m_hDC,rcTmp.left,rcTmp.top,SRCCOPY);
		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;
}

void FunAniSlide2Right(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;
	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 16;
	}
	else if (m_rcClient.Width() == 800)
	{
		nWidth = 40;
	}
	else
	{
		nWidth = 24;
	}
	i = m_rcClient.Width()/nWidth;
	CRect rcTmp = m_rcClient;
	rcTmp.OffsetRect(-m_rcClient.Width(),0);

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	if(!bExitAni)
	{
		pCT->Paint(pMemDC);
	}
	else
	{
		pMemDC->SelectBitmap(hBitmap);
	}

	while (i--)
	{
		rcTmp.OffsetRect(nWidth,0);
		dc.BitBlt(rcTmp.left,rcTmp.top,rcTmp.Width(),rcTmp.Height(),pMemDC->m_hDC,rcTmp.left,rcTmp.top,SRCCOPY);
		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;
}

void FunAniSlide2Top(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;
	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 16;
	}
	else if (m_rcClient.Width() == 800)
	{
		nWidth = 40;
	}
	else
	{
		nWidth = 24;
	}
	i = m_rcClient.Width()/nWidth;
	CRect rcTmp = m_rcClient;
	rcTmp.OffsetRect(0,rcTmp.Height());

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	if(!bExitAni)
	{
		pCT->Paint(pMemDC);
	}
	else
	{
		pMemDC->SelectBitmap(hBitmap);
	}

	while (i--)
	{
		rcTmp.OffsetRect(0,-nWidth);
		dc.BitBlt(rcTmp.left,rcTmp.top,rcTmp.Width(),rcTmp.Height(),pMemDC->m_hDC,rcTmp.left,rcTmp.top,SRCCOPY);
		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;
}
void FunAniSlide2Bottom(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif
	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;
	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 16;
	}
	else if (m_rcClient.Width() == 800)
	{
		nWidth = 40;
	}
	else
	{
		nWidth = 24;
	}
	i = m_rcClient.Width()/nWidth;
	CRect rcTmp = m_rcClient;
	rcTmp.OffsetRect(0,-rcTmp.Height());

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	if(!bExitAni)
	{
		pCT->Paint(pMemDC);
	}
	else
	{
		pMemDC->SelectBitmap(hBitmap);
	}

	while (i--)
	{
		rcTmp.OffsetRect(0,nWidth);
		dc.BitBlt(rcTmp.left,rcTmp.top,rcTmp.Width(),rcTmp.Height(),pMemDC->m_hDC,rcTmp.left,rcTmp.top,SRCCOPY);
		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;
}

void FunAniSlideSurf2Left(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 16;
	}
	else if (m_rcClient.Width() == 800)
	{
		nWidth = 40;
	}
	else
	{
		nWidth = 24;
	}
	i = m_rcClient.Width()/nWidth;
	CRect rcTmpDes = m_rcClient;
	rcTmpDes.OffsetRect(m_rcClient.Width(),0);
	CRect rcTmpSrc = m_rcClient;

	HDC memDC;
	memDC = CreateCompatibleDC(NULL);
	HBITMAP hOldBmp = (HBITMAP)::SelectObject(memDC, hBitmap);

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	pCT->Paint(pMemDC);
	 
	if(bExitAni)
	{
		pMemDC->SetAutoDraw(FALSE);
	}

	while (i--)
	{
		rcTmpDes.OffsetRect(-nWidth,0);
		rcTmpSrc.InflateRect(-nWidth,0,0,0);

		if(bExitAni)
		{
			dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),memDC,rcTmpDes.left,rcTmpDes.top,SRCCOPY);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,rcTmpSrc.Width(),rcTmpSrc.Height(),pMemDC->m_hDC,rcTmpSrc.left,rcTmpSrc.top,SRCCOPY);

		}
		else
		{
			dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),pMemDC->m_hDC,rcTmpDes.left,rcTmpDes.top,SRCCOPY);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,rcTmpSrc.Width(),rcTmpSrc.Height(),memDC,rcTmpSrc.left,rcTmpSrc.top,SRCCOPY);

		}

		
		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;

	::SelectObject(memDC, hOldBmp);		
	DeleteDC(memDC);

}

void FunAniSlideSurf2Right(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 16;
	}
	else if (m_rcClient.Width() == 800)
	{
		nWidth = 40;
	}
	else
	{
		nWidth = 24;
	}
	i = m_rcClient.Width()/nWidth;
	CRect rcTmpDes = m_rcClient;
	rcTmpDes.OffsetRect(-m_rcClient.Width(),0);
	CRect rcTmpSrc = m_rcClient;

	HDC memDC;
	memDC = CreateCompatibleDC(NULL);
	HBITMAP hOldBmp = (HBITMAP)::SelectObject(memDC, hBitmap);

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;
	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	pCT->Paint(pMemDC);

	if(bExitAni)
	{
		pMemDC->SetAutoDraw(FALSE);
	}

	while (i--)
	{
		rcTmpDes.OffsetRect(nWidth,0);
		rcTmpSrc.InflateRect(nWidth,0,0,0);
		if(bExitAni)
		{
			dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),memDC,rcTmpDes.left,rcTmpDes.top,SRCCOPY);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,rcTmpSrc.Width(),rcTmpSrc.Height(),pMemDC->m_hDC,rcTmpSrc.left,rcTmpSrc.top,SRCCOPY);

		}
		else
		{
			dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),pMemDC->m_hDC,rcTmpDes.left,rcTmpDes.top,SRCCOPY);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,rcTmpSrc.Width(),rcTmpSrc.Height(),memDC,rcTmpSrc.left,rcTmpSrc.top,SRCCOPY);

		}
		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;

	::SelectObject(memDC, hOldBmp);		
	DeleteDC(memDC);
}

void FunAniSlideSurf2Bottom(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	int nHeight = 16;
	int i = 17;
	if(m_rcClient.Height() == 240)
	{
		nHeight = 10;
	}
	else if(m_rcClient.Height() == 480)
	{
		nHeight = 20;
	}
	else
	{
		nHeight = 16;
	}
	i = m_rcClient.Height()/nHeight;
	CRect rcTmpDes = m_rcClient;
	rcTmpDes.OffsetRect(0,-m_rcClient.Height());
	CRect rcTmpSrc = m_rcClient;

	HDC memDC;
	memDC = CreateCompatibleDC(NULL);
	HBITMAP hOldBmp = (HBITMAP)::SelectObject(memDC, hBitmap);

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	pCT->Paint(pMemDC);

	if(bExitAni)
	{
		pMemDC->SetAutoDraw(FALSE);
	}


	while (i--)
	{
		rcTmpDes.OffsetRect(0,nHeight);
		rcTmpSrc.InflateRect(0,nHeight,0,0);

		if(bExitAni)
		{
			dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),memDC,rcTmpDes.left,rcTmpDes.top,SRCCOPY);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,rcTmpSrc.Width(),rcTmpSrc.Height(),pMemDC->m_hDC,rcTmpSrc.left,rcTmpSrc.top,SRCCOPY);

		}
		else
		{
			dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),pMemDC->m_hDC,rcTmpDes.left,rcTmpDes.top,SRCCOPY);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,rcTmpSrc.Width(),rcTmpSrc.Height(),memDC,rcTmpSrc.left,rcTmpSrc.top,SRCCOPY);

		}
		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;

	::SelectObject(memDC, hOldBmp);		
	DeleteDC(memDC);
}

void FunAniSlideSurf2Top(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif
	
	int nHeight = 16;
	int i = 17;
	if(m_rcClient.Height() == 240)
	{
		nHeight = 10;
	}
	else if(m_rcClient.Height() == 480)
	{
		nHeight = 20;
	}
	else
	{
		nHeight = 16;
	}
	i = m_rcClient.Height()/nHeight;
	CRect rcTmpDes = m_rcClient;
	rcTmpDes.OffsetRect(0,m_rcClient.Height());
	CRect rcTmpSrc = m_rcClient;

	HDC memDC;
	memDC = CreateCompatibleDC(NULL);
	HBITMAP hOldBmp = (HBITMAP)::SelectObject(memDC, hBitmap);

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	pCT->Paint(pMemDC);

	if(bExitAni)
	{
		pMemDC->SetAutoDraw(FALSE);
	}

	while (i--)
	{
		rcTmpDes.OffsetRect(0,-nHeight);
		rcTmpSrc.InflateRect(0,-nHeight,0,0);
		if(bExitAni)
		{
			dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),memDC,rcTmpDes.left,rcTmpDes.top,SRCCOPY);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,rcTmpSrc.Width(),rcTmpSrc.Height(),pMemDC->m_hDC,rcTmpSrc.left,rcTmpSrc.top,SRCCOPY);

		}
		else
		{
			dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),pMemDC->m_hDC,rcTmpDes.left,rcTmpDes.top,SRCCOPY);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,rcTmpSrc.Width(),rcTmpSrc.Height(),memDC,rcTmpSrc.left,rcTmpSrc.top,SRCCOPY);

		}
		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;

	::SelectObject(memDC, hOldBmp);		
	DeleteDC(memDC);
}

void FunAniSlideScreen2Left(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif
	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 16;
	}
	else if (m_rcClient.Width() == 800)
	{
		nWidth = 40;
	}
	else
	{
		nWidth = 24;
	}
	i = m_rcClient.Width()/nWidth;
	CRect rcTmpDes = m_rcClient;
	rcTmpDes.OffsetRect(m_rcClient.Width(),0);

	CRect rcTmpSrc = m_rcClient;

	HDC memDC;
	//HDC hDC = GetDC(m_hWnd);
	memDC = CreateCompatibleDC(NULL);
	//HBITMAP hBitmap = CreateCompatibleBitmap(hDC,m_rcClient.Width(),m_rcClient.Height());
	HBITMAP hOldBmp = (HBITMAP)::SelectObject(memDC, hBitmap);
	//BitBlt(memDC,m_rcClient.left,m_rcClient.top,m_rcClient.Width(),m_rcClient.Height(),hDC,0,0,SRCCOPY);
	//ReleaseDC(m_hWnd,hDC);

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	pCT->Paint(pMemDC);

	if(bExitAni)
	{
		CRect rcTmp = rcTmpDes;
		rcTmpDes = rcTmpSrc;
		rcTmpSrc = rcTmp;
		pMemDC->SetAutoDraw(FALSE);
	}

	while (i--)
	{
		rcTmpDes.OffsetRect(-nWidth,0);
		rcTmpSrc.OffsetRect(-nWidth,0);

		dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),pMemDC->m_hDC,m_rcClient.left,m_rcClient.top,SRCCOPY);

		dc.BitBlt(rcTmpSrc.left,rcTmpSrc.top,rcTmpSrc.Width(),rcTmpSrc.Height(),memDC,m_rcClient.left,m_rcClient.top,SRCCOPY);

		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;

	::SelectObject(memDC, hOldBmp);
	//DeleteObject(hBitmap);		
	DeleteDC(memDC);
}

void FunAniSlideScreen2Right(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 10;
	}
	else if(m_rcClient.Width() == 800)
	{
		nWidth = 40;
	}
	else
	{
		nWidth = 24;
	}
	i = m_rcClient.Width()/nWidth;
	CRect rcTmpDes = m_rcClient;
	rcTmpDes.OffsetRect(-m_rcClient.Width(),0);

	CRect rcTmpSrc = m_rcClient;

	HDC memDC;
	//HDC hDC = GetDC(m_hWnd);
	memDC = CreateCompatibleDC(NULL);
	//HBITMAP hBitmap = CreateCompatibleBitmap(hDC,m_rcClient.Width(),m_rcClient.Height());
	HBITMAP hOldBmp = (HBITMAP)::SelectObject(memDC, hBitmap);
	//BitBlt(memDC,m_rcClient.left,m_rcClient.top,m_rcClient.Width(),m_rcClient.Height(),hDC,0,0,SRCCOPY);
	//ReleaseDC(m_hWnd,hDC);

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	pCT->Paint(pMemDC);

	if(bExitAni)
	{
		CRect rcTmp = rcTmpDes;
		rcTmpDes = rcTmpSrc;
		rcTmpSrc = rcTmp;
		pMemDC->SetAutoDraw(FALSE);
	}

	while (i--)
	{
		rcTmpDes.OffsetRect(nWidth,0);
		rcTmpSrc.OffsetRect(nWidth,0);

		dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),pMemDC->m_hDC,m_rcClient.left,m_rcClient.top,SRCCOPY);

		dc.BitBlt(rcTmpSrc.left,rcTmpSrc.top,rcTmpSrc.Width(),rcTmpSrc.Height(),memDC,m_rcClient.left,m_rcClient.top,SRCCOPY);

		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;

	::SelectObject(memDC, hOldBmp);
	//DeleteObject(hBitmap);		
	DeleteDC(memDC);
}

void FunAniSlideScreen2Top(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	int nHeight = 16;
	int i = 17;
	if(m_rcClient.Height() == 240)
	{
		nHeight = 10;
	}
	else if(m_rcClient.Height() == 480)
	{
		nHeight = 20;
	}
	else
	{
		nHeight = 16;
	}
	i = m_rcClient.Height()/nHeight;
	CRect rcTmpDes = m_rcClient;
	rcTmpDes.OffsetRect(0,m_rcClient.Height());

	CRect rcTmpSrc = m_rcClient;

	HDC memDC;
	memDC = CreateCompatibleDC(NULL);
	HBITMAP hOldBmp = (HBITMAP)::SelectObject(memDC, hBitmap);

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	pCT->Paint(pMemDC);

	if(bExitAni)
	{
		CRect rcTmp = rcTmpDes;
		rcTmpDes = rcTmpSrc;
		rcTmpSrc = rcTmp;
		pMemDC->SetAutoDraw(FALSE);
	}

	while (i--)
	{
		rcTmpDes.OffsetRect(0,-nHeight);
		rcTmpSrc.OffsetRect(0,-nHeight);
		dc.BitBlt(rcTmpSrc.left,rcTmpSrc.top,rcTmpSrc.Width(),rcTmpSrc.Height(),memDC,m_rcClient.left,m_rcClient.top,SRCCOPY);
		dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),pMemDC->m_hDC,0,0,SRCCOPY);
		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;

	::SelectObject(memDC, hOldBmp);	
	DeleteDC(memDC);
}

void FunAniSlideScreen2Bottom(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	int nHeight = 16;
	int i = 17;
	if(m_rcClient.Height() == 240)
	{
		nHeight = 10;
	}
	else if(m_rcClient.Height() == 480)
	{
		nHeight = 20;
	}
	else
	{
		nHeight = 16;
	}
	i = m_rcClient.Height()/nHeight;
	CRect rcTmpDes = m_rcClient;
	rcTmpDes.OffsetRect(0,-m_rcClient.Height());
	CRect rcTmpSrc = m_rcClient;

	HDC memDC;
	memDC = CreateCompatibleDC(NULL);
	HBITMAP hOldBmp = (HBITMAP)::SelectObject(memDC, hBitmap);

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	pCT->Paint(pMemDC);

	if(bExitAni)
	{
		CRect rcTmp = rcTmpDes;
		rcTmpDes = rcTmpSrc;
		rcTmpSrc = rcTmp;
		pMemDC->SetAutoDraw(FALSE);
	}

	while (i--)
	{
		rcTmpDes.OffsetRect(0,nHeight);
		rcTmpSrc.OffsetRect(0,nHeight);
		dc.BitBlt(rcTmpSrc.left,rcTmpSrc.top,rcTmpSrc.Width(),rcTmpSrc.Height(),memDC,m_rcClient.left,m_rcClient.top,SRCCOPY);
		dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),pMemDC->m_hDC,m_rcClient.left,m_rcClient.top,SRCCOPY);

		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;

	::SelectObject(memDC, hOldBmp);	
	DeleteDC(memDC);
}

void FunAniSliderSurMH2Side(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 16;
	}
	else if (m_rcClient.Width() == 800)
	{
		nWidth = 40;
	}
	else
	{
		nWidth = 24;
	}
	i = m_rcClient.Width()/nWidth;
	CRect rcTmpDes = m_rcClient;
	rcTmpDes.OffsetRect(-m_rcClient.Width(),0);
	CRect rcTmpSrc = m_rcClient;

	HDC memDC;
	memDC = CreateCompatibleDC(NULL);
	HBITMAP hOldBmp = (HBITMAP)::SelectObject(memDC, hBitmap);

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;
	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	pCT->Paint(pMemDC);

	if(bExitAni)
	{
		pMemDC->SetAutoDraw(FALSE);
	}

	while (i--)
	{
		rcTmpDes.OffsetRect(nWidth,0);
		rcTmpSrc.InflateRect(nWidth,0,0,0);
		if(bExitAni)
		{
			dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),memDC,rcTmpDes.left,rcTmpDes.top,SRCCOPY);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,rcTmpSrc.Width(),rcTmpSrc.Height(),pMemDC->m_hDC,rcTmpSrc.left,rcTmpSrc.top,SRCCOPY);
		}
		else
		{
			dc.BitBlt(rcTmpDes.left,rcTmpDes.top,rcTmpDes.Width(),rcTmpDes.Height(),pMemDC->m_hDC,rcTmpDes.left,rcTmpDes.top,SRCCOPY);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,rcTmpSrc.Width(),rcTmpSrc.Height(),memDC,rcTmpSrc.left,rcTmpSrc.top,SRCCOPY);
		}
		Sleep(nSleepEscap);
	}

	delete pMemDC;
	pMemDC = NULL;

	::SelectObject(memDC, hOldBmp);		
	DeleteDC(memDC);
}

void FunAniSliderSurSide2MH(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{

}
void FunAniSliderSurMV2Side(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{

}
void FunAniSliderSurSide2MV(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{

}

void FunAniZoomOut(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 35;
#endif

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	CMemoryDC* pMemStrechDC = NULL;

	if(bExitAni)
	{
	//	pMemDC->SelectBitmap(hBitmap);
	}
	else
	{
		//pCT->Paint(pMemDC);
	}
#if 0
	int i = 25;

	BLENDFUNCTION blender;
	blender.BlendOp = AC_SRC_OVER;
	blender.BlendFlags = 0;
	blender.SourceConstantAlpha = 10;

	blender.AlphaFormat   =  0;
	pMemStrechDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	CRect rcCon=pCT->GetRect();

	//m_rcClient.SetRect(58,115,58+908,371+115);

	CRect rcClient;




	int xStep=(m_rcClient.Width()/2-rcCon.left)/24;
	int yStep=(m_rcClient.Height()/2-rcCon.top)/24;
	for(i=0;i<25;i=i+4)
	{
#ifndef UNDER_CE

		blender.SourceConstantAlpha=i*10;
		rcClient.SetRect(m_rcClient.Width()/2-i*xStep,m_rcClient.Height()/2-i*yStep
			,m_rcClient.Width()/2+i*xStep,m_rcClient.Height()/2+i*yStep);
		/*  rcClient.left=m_rcClient.Width()/2-i*xStep;
		rcClient.right=rcCon.right+i*xStep;
		rcClient.top=rcCon.top-i*yStep;
		rcClient.bottom=m_rcClient.bottom+i*yStep;*/
		//dc.BitBlt(m_rcClient.left,m_rcClient.top,m_rcClient.Width(),m_rcClient.Height(),
		//	pMemDC->m_hDC,m_rcClient.left,m_rcClient.top,SRCCOPY);



		pMemStrechDC->StretchBlt(rcClient.left,rcClient.top,rcClient.Width(),rcClient.Height(),
			pMemDC->m_hDC,rcCon.left,rcCon.top,rcCon.Width(),rcCon.Height(),SRCCOPY);
		::AlphaBlend(dc.m_hDC,rcClient.left,rcClient.top,rcClient.Width(),rcClient.Height(),pMemStrechDC->m_hDC,
			rcClient.left,rcClient.top,rcClient.Width(),rcClient.Height(),blender);

#endif
		Sleep(nSleepEscap);
	}
	blender.SourceConstantAlpha=255;

	::AlphaBlend(dc.m_hDC,rcCon.left,rcCon.top,rcCon.Width(),rcCon.Height(),pMemDC->m_hDC,
		rcCon.left,rcCon.top,rcCon.Width(),rcCon.Height(),blender);

	pMemStrechDC->SetAutoDraw(FALSE);
	delete pMemStrechDC;
	pMemStrechDC=NULL;


	pMemDC->SetAutoDraw(FALSE);
#endif

	int i = 25;

	BLENDFUNCTION blender;
	blender.BlendOp = AC_SRC_OVER;
	blender.BlendFlags = 0;
	blender.SourceConstantAlpha = 10;

	blender.AlphaFormat   =  0;
	for(i=25;i>=0;i=i-5)
	{

		pCT->SetZoom((float)i/25.0);
		pCT->Paint(pMemDC);

		blender.SourceConstantAlpha=i*10;

		CMemoryDC* pMemBKDC = NULL;

		pMemBKDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	
		pCT->PaintBackGround(pMemBKDC->m_hDC,m_rcClient);
		::AlphaBlend(pMemBKDC->m_hDC,m_rcClient.left,m_rcClient.top,m_rcClient.Width(),m_rcClient.Height(),pMemDC->m_hDC,
			m_rcClient.left,m_rcClient.top,m_rcClient.Width(),m_rcClient.Height(),blender);

		Sleep(nSleepEscap);
		
        dc.BitBlt(0,0,m_rcClient.Width(),m_rcClient.Height(),pMemBKDC->m_hDC,0,0,SRCCOPY);

		pMemBKDC->SetAutoDraw(FALSE);
		delete pMemBKDC;
		pMemBKDC=NULL;
	
	}
	pMemDC->SetAutoDraw(FALSE);
	delete pMemDC;

	pMemDC = NULL;

}

void FunAniZoomAlphaShow(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 35;
#endif

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;

	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	CMemoryDC* pMemStrechDC = NULL;
	if(bExitAni)
	{
		pMemDC->SelectBitmap(hBitmap);
	}
	else
	{
		//pCT->Paint(pMemDC);
	}
	

#if 0
	int i = 25;

	BLENDFUNCTION blender;
	blender.BlendOp = AC_SRC_OVER;
	blender.BlendFlags = 0;
	blender.SourceConstantAlpha = 10;

	blender.AlphaFormat   =  0;
    pMemStrechDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	CRect rcCon=pCT->GetRect();
	
	//m_rcClient.SetRect(58,115,58+908,371+115);

	CRect rcClient;




	int xStep=(m_rcClient.Width()/2-rcCon.left)/24;
	int yStep=(m_rcClient.Height()/2-rcCon.top)/24;
	for(i=0;i<25;i=i+4)
	{
#ifndef UNDER_CE

       blender.SourceConstantAlpha=i*10;
	   	rcClient.SetRect(m_rcClient.Width()/2-i*xStep,m_rcClient.Height()/2-i*yStep
			,m_rcClient.Width()/2+i*xStep,m_rcClient.Height()/2+i*yStep);
	 /*  rcClient.left=m_rcClient.Width()/2-i*xStep;
	   rcClient.right=rcCon.right+i*xStep;
	   rcClient.top=rcCon.top-i*yStep;
       rcClient.bottom=m_rcClient.bottom+i*yStep;*/
		//dc.BitBlt(m_rcClient.left,m_rcClient.top,m_rcClient.Width(),m_rcClient.Height(),
		//	pMemDC->m_hDC,m_rcClient.left,m_rcClient.top,SRCCOPY);
			
	  
	
	  pMemStrechDC->StretchBlt(rcClient.left,rcClient.top,rcClient.Width(),rcClient.Height(),
		 	pMemDC->m_hDC,rcCon.left,rcCon.top,rcCon.Width(),rcCon.Height(),SRCCOPY);
			::AlphaBlend(dc.m_hDC,rcClient.left,rcClient.top,rcClient.Width(),rcClient.Height(),pMemStrechDC->m_hDC,
			rcClient.left,rcClient.top,rcClient.Width(),rcClient.Height(),blender);
	
#endif
		Sleep(nSleepEscap);
	}
	blender.SourceConstantAlpha=255;
	::AlphaBlend(dc.m_hDC,rcCon.left,rcCon.top,rcCon.Width(),rcCon.Height(),pMemDC->m_hDC,
		rcCon.left,rcCon.top,rcCon.Width(),rcCon.Height(),blender);
	  
    pMemStrechDC->SetAutoDraw(FALSE);
	delete pMemStrechDC;
	pMemStrechDC=NULL;


    pMemDC->SetAutoDraw(FALSE);
#endif

	int i = 25;

	BLENDFUNCTION blender;
	blender.BlendOp = AC_SRC_OVER;
	blender.BlendFlags = 0;
	blender.SourceConstantAlpha = 10;

	blender.AlphaFormat   =  0;
	for(i=0;i<=25;i=i+5)
	{

        pCT->SetZoom((float)i/25.0);
		pCT->Paint(pMemDC);
		
		blender.SourceConstantAlpha=i*10;
#ifndef UNDER_CE
		::AlphaBlend(dc.m_hDC,m_rcClient.left,m_rcClient.top,m_rcClient.Width(),m_rcClient.Height(),pMemDC->m_hDC,
			m_rcClient.left,m_rcClient.top,m_rcClient.Width(),m_rcClient.Height(),blender);
#endif
		Sleep(nSleepEscap);
	}
	 pMemDC->SetAutoDraw(FALSE);
	delete pMemDC;
	pMemDC = NULL;

	/*if(!bMsgBox)
	{
		i = 16;
		CRect rcTmp = m_rcClient;
		rcTmp.bottom = rcTmp.top = m_rcClient.Height()/2;
		pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
		pCT->Paint(pMemDC);

		while (i--)
		{
			rcTmp.DeflateRect(0,-8,0,-8);
			dc.BitBlt(rcTmp.left,rcTmp.top,rcTmp.Width(),rcTmp.Height(),pMemDC->m_hDC,rcTmp.left,rcTmp.top,SRCCOPY);
			Sleep(nSleepEscap);
		}

		delete pMemDC;
		pMemDC = NULL;
	}*/
}

void FunAniMskHMiddle(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;

	//HBITMAP hMaskBmp = CUtil::LoadBitmapEx(strAniMask,bFromDll);
#ifdef UNDER_CE
	HBITMAP hMaskBmp = CUtil::LoadBitmapEx(L"MaskAni.bmp",TRUE);
#else
	HBITMAP hMaskBmp = CUtil::LoadBitmapEx(L"MaskAni.bmp",FALSE);
#endif

	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 8;
	}
	else if (m_rcClient.Width() == 800)
	{
		nWidth = 20;
	}
	else
	{
		nWidth = 12;
	}
	i = m_rcClient.Width()/(nWidth*2);
	CRect rcLeft = m_rcClient;
	CRect rcRight = m_rcClient;

	rcLeft.right = rcLeft.left + nWidth;
	rcRight.left = rcRight.right - nWidth;

	while(i--)
	{
		dc.AlphaBlendEx(rcLeft,hMaskBmp,rcLeft,100);
		dc.AlphaBlendEx(rcRight,hMaskBmp,rcRight,100);
		rcLeft.OffsetRect(nWidth,0);
		rcRight.OffsetRect(-nWidth,0);
		Sleep(nSleepEscap);
	}

	DeleteObject(hMaskBmp);
	hMaskBmp = NULL;

	//DWORD dwT2 = GetTickCount();
	//dwT2 -= dwT1;

	if(!bMsgBox)
	{
		i = m_rcClient.Width()/nWidth;
		CRect rcTmp = m_rcClient;
		rcTmp.left = rcTmp.right = m_rcClient.Width()/2;
		pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
		if(!bExitAni)
		{
			pCT->Paint(pMemDC);
		}
		else
		{
			pMemDC->SelectBitmap(hBitmap);
		}

		while (i--)
		{
			rcTmp.DeflateRect(-nWidth,0,-nWidth,0);
			dc.BitBlt(rcTmp.left,rcTmp.top,rcTmp.Width(),rcTmp.Height(),pMemDC->m_hDC,rcTmp.left,rcTmp.top,SRCCOPY);
			Sleep(nSleepEscap);
		}

		delete pMemDC;
		pMemDC = NULL;
	}
}



void FunAniHMiddle(HWND m_hWnd,CRect m_rcClient,CContainer* pCT,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	int nSleepEscap;
#ifdef UNDER_CE
	nSleepEscap = nAniSpeed;
#else
	nSleepEscap = 15;
#endif

	//CWindowDC dc(m_hWnd);
	//CMemoryDC* pMemDC = NULL;
	int nWidth = 10;
	int i = 20;
	if(m_rcClient.Width() == 320)
	{
		nWidth = 8;
	}
	else if (m_rcClient.Width() == 800)
	{
		nWidth = 40;
	}
	else
	{
		nWidth = 12;
	}
	i = m_rcClient.Width()/(nWidth*2);

	CRect rcTmp = m_rcClient;
	rcTmp.left = rcTmp.right = m_rcClient.Width()/2;

	HDC memDC;
	memDC = CreateCompatibleDC(NULL);
	HBITMAP hOldBmp = (HBITMAP)::SelectObject(memDC, hBitmap);

	CWindowDC dc(m_hWnd);
	CMemoryDC* pMemDC = NULL;
	pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
	pMemDC->SetAutoDraw(FALSE);
	pCT->Paint(pMemDC);

	int nWidthTemp = 0;
	while (i--)
	{
		nWidthTemp += nWidth;
		if(!bExitAni)
		{
			dc.BitBlt(m_rcClient.Width()/2-nWidthTemp,m_rcClient.top,nWidthTemp*2,m_rcClient.Height(),pMemDC->m_hDC,m_rcClient.Width()/2-nWidthTemp,m_rcClient.top,SRCCOPY);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,m_rcClient.Width()/2-nWidthTemp,m_rcClient.Height(),memDC,nWidthTemp,m_rcClient.top,SRCCOPY);
			dc.BitBlt(m_rcClient.Width()/2+nWidthTemp,m_rcClient.top,m_rcClient.Width()/2-nWidthTemp,m_rcClient.Height(),memDC,m_rcClient.Width()/2,m_rcClient.top,SRCCOPY);
		}
		else
		{
			dc.BitBlt(nWidthTemp,m_rcClient.top,m_rcClient.Width()-nWidthTemp*2,m_rcClient.Height(),pMemDC->m_hDC,nWidthTemp,m_rcClient.top,SRCCOPY);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,nWidthTemp,m_rcClient.Height(),memDC,m_rcClient.Width()/2-nWidthTemp,m_rcClient.top,SRCCOPY);
			dc.BitBlt(m_rcClient.Width()-nWidthTemp,m_rcClient.top,nWidthTemp,m_rcClient.Height(),memDC,m_rcClient.Width()/2,m_rcClient.top,SRCCOPY);
		}
	}

	delete pMemDC;
	pMemDC = NULL;	
	::SelectObject(memDC, hOldBmp);		
	DeleteDC(memDC);
}


void CWnd::AnimateShow(CContainer* pCT,AnimateType aniType,int nAniSpeed,HBITMAP hBitmap,BOOL bMsgBox,BOOL bExitAni)
{
	//DWORD dwT1 = GetTickCount();
	if(AniMskVMiddle2Side == aniType)
	{
		FunAniMskVMiddle2Side(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniVMiddle2Side == aniType)
	{
		FunAniVMiddle2Side(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniMskHMiddle2Side == aniType)
	{
		FunAniMskHMiddle2Side(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniHMiddle2Side == aniType)
	{
		FunAniHMiddle2Side(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSlide2Left == aniType)
	{
		FunAniSlide2Left(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSlide2Right == aniType)
	{
		FunAniSlide2Right(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSlide2Top == aniType)
	{
		FunAniSlide2Top(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSlide2Bottom == aniType)
	{
		FunAniSlide2Bottom(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSlideSurf2Left == aniType)
	{
		FunAniSlideSurf2Left(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSlideSurf2Right == aniType)
	{
		FunAniSlideSurf2Right(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSlideSurf2Bottom == aniType)
	{
		FunAniSlideSurf2Bottom(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSlideSurf2Top == aniType)
	{
		FunAniSlideSurf2Top(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSlideScreen2Left == aniType)
	{
		FunAniSlideScreen2Left(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSlideScreen2Right == aniType)
	{
		FunAniSlideScreen2Right(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSlideScreen2Top == aniType)
	{
		FunAniSlideScreen2Top(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSlideScreen2Bottom == aniType)
	{
		FunAniSlideScreen2Bottom(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniZoomOut == aniType)
	{
		FunAniZoomOut(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniZoomAlphaShow == aniType)
	{
		FunAniZoomAlphaShow(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSliderSurMH2Side == aniType)
	{
		FunAniSliderSurMH2Side(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSliderSurSide2MH == aniType)
	{
		FunAniSliderSurSide2MH(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSliderSurMV2Side == aniType)
	{
		FunAniHMiddle(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
		//FunAniSliderSurMV2Side(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if(AniSliderSurSide2MV == aniType)
	{
		FunAniSliderSurSide2MV(m_hWnd,m_rcClient,pCT,nAniSpeed,hBitmap,bMsgBox,bExitAni);
	}
	else if (30 == aniType)
	{
		if(bExitAni)
		{
			HDC memDC;
			memDC = CreateCompatibleDC(NULL);
			HBITMAP hOldBmp = (HBITMAP)::SelectObject(memDC, hBitmap);
			CWindowDC dc(m_hWnd);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,m_rcClient.Width(),m_rcClient.Height(),memDC,m_rcClient.left,m_rcClient.top,SRCCOPY);
			::SelectObject(memDC, hOldBmp);		
			DeleteDC(memDC);
		}
		else
		{
			CWindowDC dc(m_hWnd);
			CMemoryDC* pMemDC = NULL;
			pMemDC = new CMemoryDC(dc.m_hDC,m_rcClient);
			pCT->Paint(pMemDC);
			dc.BitBlt(m_rcClient.left,m_rcClient.top,m_rcClient.Width(),m_rcClient.Height(),pMemDC->m_hDC,m_rcClient.left,m_rcClient.top,SRCCOPY);
			delete pMemDC;
			pMemDC = NULL;
		}

	}
	else
	{
	}
	//DWORD dwT2 = GetTickCount();
	//dwT2 -= dwT1;
}